package com.dwork.base.controller.scanning;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.reflections.Reflections;

public final class AnnoManageUtil {

    /**
     * 获取指定文件下面的RequestMapping方法保存在mapp中
     *
     * @param packageName
     * @return
     */
    public static Map<String, ExecutorBean> getRequestMappingMethod(String packageName) {
    	// 存放url和ExecutorBean的对应关系
        Map<String, ExecutorBean> mapp = new HashMap<String, ExecutorBean>();
        String[] str = null;
        if(packageName!=null&&!"".equals(packageName)){
        	str = packageName.split(",");
        	for(String pstr : str){
        		Reflections reflections = new Reflections(pstr);
                Set<Class<?>> classesList = reflections.getTypesAnnotatedWith(Sign.class);

                
                for (Class classes : classesList) {
                    //得到该类下面的所有方法
                    Method[] methods = classes.getDeclaredMethods();
                    classes.getName();classes.getSimpleName();
                    for (Method method : methods) {
                        //得到该类下面的RequestMapping注解
                    	Tagg tagging = method.getAnnotation(Tagg.class);
                        if (null != tagging) {
                            ExecutorBean executorBean = new ExecutorBean();
                            try {
                                executorBean.setObject(classes.newInstance());
                            } catch (InstantiationException e) {
                                e.printStackTrace();
                            } catch (IllegalAccessException e) {
                                e.printStackTrace();
                            }
                            executorBean.setMethod(method);
                            mapp.put(tagging.value(), executorBean);

                        }
                    }
                }
        	}
        	
        }
        
        return mapp;
    }

}